package com.wwwarehouse.common.adapter.filter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.common.R;
import com.wwwarehouse.common.bean.filter.FilterBean;

import java.util.List;

/**
 *  单选筛选器的Adapter
 * Created by ShineF on 2017/7/11 0011.
 */

public class FilterSingleAdapter extends BaseAdapter {
    private Context mContext;
    private List<FilterBean> mList;
    private ViewHolder mHolder;

    public FilterSingleAdapter(Context context, List<FilterBean> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_drawer_filter_single, null);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        final FilterBean filterBean = mList.get(position);
        if (filterBean.isSelect()) {
            mHolder.name.setActivated(true);
            mHolder.icon.setVisibility(View.VISIBLE);
        } else {
            mHolder.name.setActivated(false);
            mHolder.icon.setVisibility(View.GONE);
        }

        mHolder.name.setText(filterBean.getText());

        return convertView;
    }

    class ViewHolder{
        TextView name;
        ImageView icon;

        public ViewHolder(View view){
            name = (TextView) view.findViewById(R.id.tv_name);
            icon = (ImageView) view.findViewById(R.id.iv_icon);
        }
    }
}
